<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="box">
        <button @click="type='no1'">no1</button>
        <button @click="type='no2'">no2</button>
        <keep-alive>
            <component :is="type"></component>
        </keep-alive>
    </div>
    <template id="no1">
        <div>
            no1
        </div>
    </template>
    <template id="no2">
        <div>
            no2
        </div>
    </template>
</body>
<script src="../js/vue.js"></script>
<script>
    Vue.component('no1',{
        template:'#no1',
        created(){
            console.log("创建完成后");
        },
        mounted(){
            console.log("渲染完成后");
        },
        activated(){
            console.log('no1已被激活');
        },
        deactivated(){
            console.log('no1已被停用');
            
        }
    })
    Vue.component('no2',{
        template:'#no2'
    })
    new Vue({
        el:"#box",
        data:{
            type:'no1'
        }
    })
</script>
</html>